import React, {Component} from 'react'
import { Link } from 'react-router'
import Writebar from './writebar'
import './sm-extend.min.css'
import './sm.min.css'
import './index.css'
import $ from 'jquery'

class Content extends Component{
    constructor(){
        super();
    }

    handck(){
        let recipients = $('.recipients').val();
        let titleinput = $('.titleinput').val();
        let theme = $('.theme').val();
        let sendtor = localStorage.getItem('name');
        var data={
            recipients:recipients,
            titleinput:titleinput,
            theme:theme,
            sendtor:sendtor
        }
        if(recipients==""||titleinput==""||theme==""){
            alert('请将信息填写完整');
        }else{
            $.post('http://127.0.0.1:8080/send',data,function(data,textStatus,xhr){
                if(String(data)=="nopeople"){
                    alert('收件人账号填写错误');
                }else{
                    alert('发送成功');
                    $('.recipients').val('');
                    $('.titleinput').val('');
                    $('.theme').val('');
                    console.log(data);
                }

            })
        }
    }
    componentDidMount=()=>{

    var forname = localStorage.getItem('forname');
    console.log(forname)
    if(forname==undefined){
    $('recipients').val('')
    }else{
        $('.recipients').val(forname);
    }

    }
    render(){

        return(
            <div>
            <div className="content">
                <div className="row no-gutter">
                    <div className="col-100 titlediv">
                        <div className="col-20"><span className="titlefont">收件人</span></div>
                        <div className="col-75 titleinputdiv">
                        <input type="text" className=" recipients"/>
                        </div>
                        </div>
                    <div className="col-100 titlediv">
                        <div className="col-20"><span className="titlefont">标题</span></div>
                        <div className="col-75 titleinputdiv">
                         <input type="text" className="titleinput"/>
                        </div>
                    </div>
                    <div className="col-100 themediv">
                        <div className="col-20"><span className="themefont">主题</span></div>

                        <textarea className="col-75 theme">

                        </textarea>
                    </div>
                </div>
            <div className="content-block">
            <div className="row">

            <div className="col-100"><a className="button button-big button-fill button-success" onClick={this.handck.bind(this)}>发送</a></div>
            </div>
            </div>
            </div>
                <Writebar/>
            </div>
         )

    }

}


export default Content